Skip to content

Show document images from the local blob store - #1895

Closed
Polleps wants to merge 1 commit into
developfrom
claude/nice-rubin-82ayvd-document-images
Closed

Polleps wants to merge 1 commit into
developfrom
claude/nice-rubin-82ayvd-document-images

Conversation

@Polleps

@Polleps Polleps commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Related Issues

Reported bug: images in documents show "Failed to load image" (regression). No issue number yet.

Root cause

When you upload an image into a document, Store.uploadFiles writes the File's downloadURL as ${serverUrl}/download/files/<blake3>. The image node keeps only that URL as its src. The bytes stay in the local ClientDb, and the outbox drain pushes them to the server later (maybePushBlobForResource).

In a browser-only (local-only) drive, nothing is pushed. isLocalOnlySubject skips posting both the commit and the bytes, so no server has the blob, and GET /download/files/<hash> returns 404. MarkdownEditorImage (chunks/RTE/ImagePicker.tsx) passed that URL straight to <img>. onError then fired and set a sticky imageError, which shows "Failed to load image."

File previews, glyphs and avatars did not have this problem. They go through useFileObjectUrl, which serves the local copy as a blob: URL. The document image node never did.

This became a regression when browser-only drives turned into the normal path. openPrivateHome creates the home drive with localOnly: isOriginWithoutNode(...), and DriveTemplateSetup creates drives with localOnly: !!getManagedPortalUrl(). Both arrived in 4a3a0bf ("Batch: storage path simplification…", #1852). That commit is also the root of this repository's imported history, so I can't narrow it down to a single original PR (#1772/#1777/#1779/#1780/#1784/#1782) from here.

I ruled out the server side. Against a normal synced drive, /download/files/<hash> returns 200 with application/octet-stream, nosniff and attachment, and Chromium renders the image fine, including after a reload.

Fix

  • @tomic/lib: blobSubjectFromDownloadUrl(url) maps a content-addressed /download/files/<64-hex> URL back to atomic:blob:<hash>. It returns undefined for any other URL, including legacy /download/files/<name>.jpg paths.
  • @tomic/react: useBlobObjectUrl(blobDid, fallback) is the blob-reference half of useFileObjectUrl, which now delegates to it. Its behaviour is unchanged.
  • ImagePicker.tsx:
    • Renders the local copy when one exists and falls back to the URL otherwise.
    • Waits for the local lookup instead of racing it.
    • Keys the error state by src, so a new src gets a fresh attempt.
    • The document itself still stores the portable URL.
  • The image picker logged a React "unique key" warning whenever it opened. The i18n transform turned Choose an image <Column/> and Textual Description <TextArea/> into keyless arrays. Wrapping the text in <span> fixes it. The .po changes are just those two re-keyed messages.

Tests

  • New browser/e2e/tests/document-image.spec.ts: creates a browser-only drive and a document, uploads a freshly generated PNG through the slash-command image picker, and asserts the image decodes from a blob: src with no error. It checks this again after a reload. The PNG is generated each run because blobs are content-addressed, and a fixed fixture already on the server would hide the bug.
    • Before the fix: fails. The editor shows "Failed to load image." and there is no <img>.
    • After the fix: passes.
  • subject.test.ts: unit tests for blobSubjectFromDownloadUrl.
  • Also re-ran file-upload-offline.spec.ts (covers the refactored useFileObjectUrl) and cover-reposition.spec.ts: 4 passed.
  • lint and typecheck pass for lib, react, data-browser and e2e. browser/lib vitest: 1081 passed. data-browser RTE vitest: passed.

Checklist

  • Add changelog entry linking to issue, describe API changes
  • Add or update tests if needed
  • Update docs if needed (TESTING_COVERAGE.md)

No screenshots: the only visible change is that the image renders again where it used to show the error placeholder.

🤖 Generated with Claude Code

https://claude.ai/code/session_01P648McUYrscNsheXY5Ya81


Generated by Claude Code

An image uploaded into a document keeps only its `downloadURL`
(`<server>/download/files/<hash>`) in the node's `src`. In a browser-only
drive (the default for the hosted distribution and for drives created
there), neither the File's commit nor its bytes ever reach a server, so
that URL answers 404 and the editor's node view showed "Failed to load
image". File previews did not have this problem because they resolve
the bytes locally through `useFileObjectUrl`; the editor image never did.

- `@tomic/lib`: `blobSubjectFromDownloadUrl` maps a content-addressed
  download URL back to its `atomic:blob:<hash>`.
- `@tomic/react`: `useBlobObjectUrl`, the blob-reference half of
  `useFileObjectUrl`, for callers without a File resource.
- `ImagePicker`: render the local copy when there is one, fall back to
  the URL otherwise, wait for the lookup instead of racing it, and key
  the error state by src so a new src gets a fresh attempt. The document
  still stores the portable URL.
- Wrap two label texts in spans: the i18n transform turned them into
  keyless arrays, which logged a React key warning whenever the picker
  opened.

Adds `document-image.spec.ts`, which fails with "Failed to load image."
before this change and passes after, including across a reload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P648McUYrscNsheXY5Ya81
@Polleps
Polleps marked this pull request as ready for review September 29, 2026 13:28
joepio added a commit that referenced this pull request Sep 30, 2026
…ent images, onboarding recovery fixes (#1915)

Lands #1889 (edit agents, skills and MCP servers in a dialog), #1890 (sidebar account menu in place of the App panel), #1891 (share dialog role select stays open), #1895 (document images from the local blob store) and #1917 (onboarding recovery, metadata request bursts, local bootstrap), tested together on Mancave.
@joepio joepio closed this Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants